package lamma.lab2.job;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Future;

/**
 * @author maxcellent
 *
 */
public interface AsyncStep {
	
	/**
	 * @author maxcellent
	 *
	 */
	public static class Builder {
		
		/**
		 * @param future
		 * @return
		 */
		public static AsyncStep fromFuture(final Future<?> future) { 			
			return new AsyncStep() {
				@Override
				public boolean isDone() {
					return future.isDone();
				}
			};
		}
		
		/**
		 * @param <T>
		 * @param futures
		 * @return
		 */
		public static <T> List<AsyncStep> fromFutures(final Collection<Future<T>> futures) {
			List<AsyncStep> steps = new ArrayList<AsyncStep>();
			
			for (final Future<?> future : futures) {
				steps.add(new AsyncStep() {
					@Override
					public boolean isDone() {
						return future.isDone();
					}
				});
			}
			
			return steps;
		}
	}
	
	/**
	 * @return
	 */
	boolean isDone();
	
}
